//
//  BPCouponTableViewCell.m
//  BabyPhotograph
//
//  Created by cesh on 2017/2/6.
//  Copyright © 2017年 cesh. All rights reserved.
//

#import "BPCouponTableViewCell.h"

@interface BPCouponTableViewCell()

@property (weak, nonatomic) IBOutlet UIImageView *bgImg;
@property (weak, nonatomic) IBOutlet UILabel *couponNameLbl;
@property (weak, nonatomic) IBOutlet UILabel *couponDeadlineLbl;
@property (weak, nonatomic) IBOutlet UILabel *couponConditionLbl;

@property (strong, nonatomic) UILabel *numberLbl;
@property (strong, nonatomic) UILabel *unitLbl;

@end

@implementation BPCouponTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setOutdated:(BOOL)outdated {
    _outdated = outdated;
    if (outdated) {
        self.bgImg.image = [UIImage imageNamed:@"card_2"];
        self.numberLbl.textColor =  [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1/1.0];
        self.unitLbl.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1/1.0];
        self.couponNameLbl.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1/1.0];
        self.couponDeadlineLbl.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1/1.0];
        self.couponConditionLbl.textColor = [UIColor colorWithRed:155/255.0 green:155/255.0 blue:155/255.0 alpha:1/1.0];
    }
}

- (void)setCouponType:(CouponType)couponType {
    switch (couponType) {
        case CouponTypeMoney:
        {
            UILabel *RMB = [[UILabel alloc]init];
            RMB.text = @"¥";
            RMB.font = [UIFont fontWithName:@"PingFangSC-Medium" size:17.9];
            RMB.textColor = [UIColor colorWithRed:245/255.0 green:166/255.0 blue:35/255.0 alpha:1/1.0];
            [RMB sizeToFit];
            RMB.origin = CGPointMake(screenW - 116, 48);
            self.unitLbl = RMB;
            [self addSubview:RMB];
            
            UILabel *money = [[UILabel alloc]init];
            
            money.text = self.data[@"money"];
            money.font = [UIFont fontWithName:@"PingFangSC-Medium" size:35.7];
            money.textColor = [UIColor colorWithRed:245/255.0 green:166/255.0 blue:35/255.0 alpha:1/1.0];
            [money sizeToFit];
            money.origin = CGPointMake(screenW - 100, 30);
            self.numberLbl = money;
            [self addSubview:money];
        }
            break;
        case CouponTypeDiscount:
        {
            UILabel *discount = [[UILabel alloc]init];
            discount.text = @"9.0";
            discount.font = [UIFont fontWithName:@"PingFangSC-Medium" size:35.7];
            discount.textColor = [UIColor colorWithRed:245/255.0 green:166/255.0 blue:35/255.0 alpha:1/1.0];
            [discount sizeToFit];
            discount.origin = CGPointMake(screenW - 110, 30);
            self.numberLbl = discount;
            [self addSubview:discount];
            
            UILabel *zhe = [[UILabel alloc]init];
            zhe.text = @"折";
            zhe.font = [UIFont fontWithName:@"PingFangSC-Medium" size:17.9];
            zhe.textColor = [UIColor colorWithRed:245/255.0 green:166/255.0 blue:35/255.0 alpha:1/1.0];
            [zhe sizeToFit];
            zhe.origin = CGPointMake(screenW - 55, 48);
            self.unitLbl = zhe;
            [self addSubview:zhe];
        }
            break;
        default:
            break;
    }
}

- (void)setData:(NSDictionary *)data {
    _data = data;
    long canUseLong = [data[@"canUse"] longValue];
    BOOL canUse = (canUseLong == 1) ? YES : NO;
    self.outdated = !canUse;
    
    self.couponNameLbl.text = data[@"title"];
    self.couponDeadlineLbl.text = [NSString stringWithFormat:@"有效期至%@", data[@"time_str"]];
    self.couponConditionLbl.text = data[@"desc"];
}

@end
